package com.hvgroup.modules.sanic.domain.qo;


import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
 * TODO 2025年6月4日  DIFY专属问答类
 */
@Data
public class QaQuestionQuery {

    /**
     * 用户输入的问题
     */
    private String query;

    /**
     * 问答类型，例如：COMMON_QA、DOC_QA
     */
    private String qaType;

    /**
     * 前端生成的会话唯一 ID
     */
    private AtomicReference<Long> chatId;

    /**
     * Dify 生成的上下文 conversationId（用于多轮对话）, 在多轮问答是必传的
     */
    private String conversationId;

    private String responseMode = "streaming";

    private String user;

    private Long userId;

    private String appId;

    private String fileKey;

    private String fileUrl;

    private String fileSize;


    private String type;
    private String transferMethod;
    private String uploadFileId;
    private Boolean isFile;
    private Map<String, Object> file = new HashMap();



    public Map<String, Object> builderParamBody() {
        Map<String, Object> param = new HashMap<>();
        param.put("query", query);
        param.put("response_mode", responseMode);
        param.put("user", user);
        param.put("conversation_id", conversationId);

        Map<String, Object> inputs = new HashMap<>();
        inputs.put("qa_type", qaType);
        if (Boolean.TRUE.equals(this.isFile)) {
            file.put("type",this.type);
            file.put("transfer_method",transferMethod);
            file.put("upload_file_id",this.uploadFileId);
            inputs.put("file", this.file);

        }
        param.put("inputs", inputs);
        return param;
    }

    public synchronized Long getChatId() {
        return chatId.get();
    }



    public synchronized void setChatId(Long chatId) {
        if (this.chatId == null) {
            this.chatId = new AtomicReference<>(chatId);
        } else {
            this.chatId.set(chatId);
        }
    }



}
